home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 4802 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.1 KB  |  53 lines

  1. Path: nic.wat.hookup.net!news
  2. From: xenon@the-fix.sos.on.ca
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Checking to See if a File Exists
  5. Date: Wed, 07 Feb 1996 02:05:54 GMT
  6. Organization: HookUp Communication Corporation, Waterloo, Ontario, CANADA
  7. Message-ID: <4f92ea$op9@nic.wat.hookup.net>
  8. References: <DLtI7G.HpE@midway.uchicago.edu> <3109a461.960289@ixnews1.ix.netcom.com>
  9. NNTP-Posting-Host: slip31.sos.on.ca
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. n4jvp@ix.netcom.com (n4jvp) wrote:
  13.  
  14. >On Sat, 27 Jan 1996 02:14:04 GMT, jaj3@kimbark.uchicago.edu (josef
  15. >jurek) wrote:
  16.  
  17. >>
  18. >>How does one check from a C program to see whether a file
  19. >>exists or not?
  20. >>
  21. >>Thank you,
  22. >>
  23. >> --
  24. >>
  25. >>josef jurek
  26. >>jaj3@kimbark.uchicago.edu
  27. >>
  28.  
  29.     An easy way is too see what fopen is returning....
  30.  
  31. #include <stdio.h>
  32.  
  33. int main()
  34. {
  35.     FILE *fp    */pointer to file /*
  36.     
  37.     if((fp=fopen("filename.ext","r"))==NULL)   */open the file, if it
  38. doesn't exist, fopen will return NULL/*
  39.     {
  40.         printf("Error:  File not found");
  41.         
  42.     }
  43.     else
  44.     {
  45.         printf("File succesfully opened!");
  46.     }
  47.     return 0;  */can't forget that..../*
  48. }
  49.  
  50.  
  51.  
  52.  
  53.